package com.jch.group_msg;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LineBasedFrameDecoder;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

import java.nio.charset.StandardCharsets;

public class DemoChannelInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {

        // 基于换行符 "\r\n"
        ch.pipeline().addLast(new LineBasedFrameDecoder(1024));
        ch.pipeline().addLast(new StringDecoder(StandardCharsets.UTF_8)); // String 解码器
        ch.pipeline().addLast(new StringEncoder(StandardCharsets.UTF_8)); // String 编码器
        ch.pipeline().addLast(new DemoServerHandler());// 自定义处理器
    }
}
